package com.ndkj.rpcserver.proxy.chain;

import java.lang.reflect.Method;

/**
 * Consumer服务调用Mock处理链
 */
public class MethodMockChain implements Handler {

    @Override
    public boolean canHandle() {
        // 服务mock
        String mock = System.getProperty("mock");
        return mock != null && !mock.equals("");
    }

    @Override
    public Object process(Class interfaceClazz, String version, Object proxy, Method method, Object[] args) {
        // 服务mock
        String mock = System.getProperty("mock");
        if (mock.startsWith("return:")) {
            return mock.replace("return:", "");
        }
        throw new RuntimeException("The JVM parameter is set abnormally");
    }

}
